import React, { PureComponent } from 'react'
import { View, Text } from '@tarojs/components'
import { SpFilterDrawer } from '@/components'
import './index.scss'


export default class FilterBlock extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      showFilter: false,
      filterParams: {}
    }
  }

  handleShowDrawer = () => {
    this.setState({
      showFilter: true
    })
  }

  handleCloseDrawer = () => {
    this.setState({
      showFilter: false
    })
  }

  filterData = () => {
      return [
        {
          itemLabel: '上下架状态',
          itemValue: 'is_shelves',
          dataSource: [
            { value: 'false', label: '全部' },
            { value: 'true', label: '已上架' },
            { value: 'down', label: '已下架' }
          ]
        },
        {
          itemLabel: '商品分类',
          itemValue: 'category',
          dataSource: [{ value: '', label: '全部' },...this.props.category_list]
        }
      ]
  }

  //点击确认筛选
  handleSubmitParams = (params) => {
    const { onSubmitParams = () => {} } = this.props
    onSubmitParams(params)
    this.setState({
      showFilter: false
    })
  }


  render() {
    const { showFilter } = this.state

    const { pageType, onOrderClick = () => {}, orderBy, title = '订单筛选' } = this.props

    return (
      <View className='filterContent'>
        <View className='comp-order-list-filterBlock'>
          <View className='filterTip' onClick={this.handleShowDrawer}>
            {/* <View className='iconfont icon-shaixuan2'></View> */}
            <View className='text'>筛选</View>
          </View>
        </View>

        <SpFilterDrawer
          filterTitle={title}
          filterData={this.filterData()}
          visible={showFilter}
          onCloseDrawer={this.handleCloseDrawer}
          onConfirm={this.handleSubmitParams}
        />
      </View>
    )
  }
}
